﻿using Lanbt.Core.Utility.Extent;
using NLog;

namespace Lanbt.Core.Utility.Helper
{
    public static class LogHelper<T>
    {

        private static readonly Logger log = LogManager.GetLogger(typeof(T).FullName);

        public static void Trace(object msg, Exception ex = null)
        {
            if (ex == null)
            {
                log.Trace(msg.ParseToString());
            }
            else
            {
                log.Trace(ex, msg.ParseToString());
            }
        }

        public static void Debug(object msg, Exception ex = null)
        {
            if (ex == null)
            {
                log.Debug(msg.ParseToString());
            }
            else
            {
                log.Debug(ex, msg.ParseToString());
            }
        }

        public static void Info(object msg, Exception ex = null)
        {
            if (ex == null)
            {
                log.Info(msg.ParseToString());
            }
            else
            {
                log.Info(ex, msg.ParseToString());
            }
        }

        public static void Warn(object msg, Exception ex = null)
        {
            if (ex == null)
            {
                log.Warn(msg.ParseToString());
            }
            else
            {
                log.Warn(ex, msg.ParseToString());
            }
        }

        public static void Error(object msg, Exception ex = null)
        {
            if (ex == null)
            {
                log.Error(msg.ParseToString());
            }
            else
            {
                log.Error(ex, msg.ParseToString());
            }
        }

        public static void Error(Exception ex)
        {
            if (ex != null)
            {
                log.Error(ex);
            }
        }

        public static void Fatal(object msg, Exception ex = null)
        {
            if (ex == null)
            {
                log.Fatal(msg.ParseToString());
            }
            else
            {
                log.Fatal(ex, msg.ParseToString());
            }
        }

        public static void Fatal(Exception ex)
        {
            if (ex != null)
            {
                log.Fatal(ex);
            }
        }
    }
}
